using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Microsoft.TeamFoundation.Server;

namespace WIAssistant
{
    /// <summary>
    /// Used to create the tree for the iterations
    /// </summary>
    public class IterationNode : INotifyPropertyChanged
    {
        public string IterationPath { get; set; }
        public string Uri { get; set; }
        public ProjectInfo ProjectInfo { get; set; }
        public bool IsProjectLevel { get; set; }

        // Get the last part of the path
        public string PathEnd
        {
            get
            {
                int lastIndex = IterationPath.LastIndexOf("\\");
                if (lastIndex > 0)
                    return IterationPath.Substring(IterationPath.LastIndexOf("\\") + 1);
                else
                    return IterationPath;
            }
        }
        
        public override string ToString()
        {
            return PathEnd;
        }


        public ObservableCollection<IterationNode> Children
        {
            get { return _children; }
            set
            {
                _children = value;
                OnPropertyChanged("Children");
            }
        }

        

        private ObservableCollection<IterationNode> _children = new ObservableCollection<IterationNode>();

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}